<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <title>新增</title>

    <!-- CSS -->
    <link rel="stylesheet" href="../../static/plugins/layui/css/layui.css" th:href="@{plugins/layui/css/layui.css}"/>
    <link rel="stylesheet" href="../../static/mycss/common.css" th:href="@{mycss/main.css}"/>

</head>
<body>
<input type="hidden" name="uuid"/>
<div>
    <div style="margin:10px;">
        <form class="layui-form">
            <div class="layui-form-item">
                <blockquote class="layui-elem-quote">
                    <div class="layui-inline">
                        <button class="layui-btn" id="demoSave" lay-submit="" lay-filter="*">保存</button>
                    </div>
                    <div class="layui-inline">
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-form-mid layui-word-aux"> <span style="color: red"> （注：如果编号为空，则根据递增规则自动生成编号;默认初始编号为：100000）</span></div>
                    </div>
                </blockquote>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="name" lay-verify="required" placeholder=""/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="number" placeholder=""/>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">登录名</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="loginName" lay-verify="required" placeholder=""/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="password" readonly placeholder="默认密码为：111111"/>
                    </div>
                </div>
            </div>

        </form>
    </div>
</div>

<!-- JS -->
<script type="text/javascript" src="../../static/plugins/layui/layui.js" th:src="@{plugins/layui/layui.js}"></script>
<script>
    layui.use(['form', 'layer'], function () {
        var $ = layui.$;
        var form = layui.form;
        var layer = layui.layer;

        /**
         * 表单提交 监听
         */
        form.on('submit(*)', function (data) {
            var subInfo;//提交信息
            //表单验证
            if(1!=1){
                layer.msg('提示信息',{icon:5,time:1000});
                return false;
            }else {
                subInfo = JSON.stringify(data.field);
                //提交
                $.ajax({
                    url: 'landerAdd',
                    type: 'post',
                    data: {subInfo: subInfo},
                    dataType: 'text',//服务器返回的数据类型。
                    success: function (result) {
                        //保存后关闭当前弹出层:1.得到当前iframe层的索引;2.再执行关闭
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.layer.msg("保存成功", {icon: 1, time: 1500});
                    },
                    error: function (e) {
                        layer.msg("出现异常", {icon: 5, time: 1000});
                    }
                });
            }
            //注：此处必须有这个，因为这里我用了自己的ajax来提交表单，如果不return false，form监听程序本身也会触发提交，可能会出现莫名奇妙的错误
            return false;
        });

    });
</script>

</body>
</html>